#include "DynamicArray.h"
#include <iostream>
#include <string>

class Student
{
public:
    std::string name;
    int age;
    Student():name(""), age(0){}
    Student(std::string name, int age):name(name), age(age){}

};

void PrintStu(ElementType student)
{
    Student *s = (Student *)student;
    std::cout<<"Name:"<<s->name<<", Age:"<<s->age<<std::endl;
}

int main()
{
    DynamicArray a;
    Student s0("hmq", 20);
    Student s1("zhangsan", 21);
    Student s2("lisi", 22);
    Student s3("wangwu", 23);
    Student s4("zhaoliu", 24);

    // 尾插
    a.InsertTail(&s0);
    a.InsertTail(&s1);
    a.InsertTail(&s2);
    // a.show(PrintStu);
#if 0
    // 头插
    a.InsertHead(&s3);
    // a.show(PrintStu);
#endif

#if 0
    // 中间插
    a.InsertByIndex(1, &s4);
    a.show(PrintStu);
#endif

#if 0
    // 按位置删
    a.RemoveByIndex(1);
    a.show(PrintStu);
#endif

#if 0
    // 按值删除
    a.RemoveByElement(&s4);
    a.show(PrintStu);
#endif

#if 0
    // 按位置查找
    ElementType *p = a.FindByIndex(2);
    if(p) //p不为空就表示找到了
    {
        PrintStu(*p);
    }
    else
    {
        std::cout<<"没找到"<<std::endl;
    }
#endif

#if 0
    // 按值查找
    DynamicArray result = a.FindByElement(&s0);
    result.show(PrintStu);
#endif

#if 0
    // 修改
    a.UpdateByIndex(0,&s2);
    a.show(PrintStu);

    a.UpdateByElement(&s0,&s1);
    a.show(PrintStu);
#endif

#if 0
    // 排序
    a.Sort();
    a.show(PrintStu);
#endif

#if 0
    // 去重
    a.Duplicate();
    a.show(PrintStu);
#endif

#if 1
    // 归并
    Student s[4];
    s[0].name = "tgc";
    s[0].age = 25;

    s[1].name = "wkj";
    s[1].age = 26;

    s[2].name = "wkj";
    s[2].age = 26;

    s[3].name = "ljj";
    s[3].age = 28;

    DynamicArray a1;
    for(int i = 0; i < 2; i++)
    {
        a1.InsertTail(&s[i]);
    }
    DynamicArray a2;
    for(int i = 2; i < 4; i++)
    {
        a2.InsertTail(&s[i]);
    }
    a1.show(PrintStu);
    a2.show(PrintStu);
    // DynamicArray a3 = a1.Merge(a2);
    // a3.show(PrintStu);

    // 找交集
    a1.FdInterSctn(a2).show(PrintStu);
    // 找并集
    a1.FindUnionSet(a2).show(PrintStu);
    // 找补集
    a1.FindDifference(a2).show(PrintStu);
#endif


    return 0;
}